//
//  BCShopViewManager.m
//  BangcaiBuy
//
//  Created by Liang Zhang on 16/7/27.
//  Copyright © 2016年 BCB. All rights reserved.
//

#import "BCShopViewManager.h"

@implementation BCShopViewManager

+ (void)loadDataToStuff {
    [[CoreDataStorageController sharedModel] removeAllElements:@"STUFF"];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"LocalStuffData" ofType:@"plist"];
    NSArray *stuffArray = [NSArray arrayWithContentsOfFile:path];
    [stuffArray enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        STUFF *model = [[CoreDataStorageController sharedModel] insertElementIntoEntity:@"STUFF"];
        model.uuid = obj[@"uuid"];
        model.name = obj[@"name"];
        model.discribtion = obj[@"discribtion"];
        model.icon = obj[@"icon"];
        model.price = obj[@"price"];
        model.unit = obj[@"unit"];
        model.category = obj[@"category"];
        model.subcategory = obj[@"subcategory"];
    }];
}

+ (NSArray *)readSpecialOfferStuffs {
    NSArray *data = [[CoreDataStorageController sharedModel] selectElementFromEntity:@"STUFF" PredicateFromat:nil SortKey:nil Limit:10 Ascending:NO];
    return data;
}

+ (NSArray *)readAllStuffs {
    NSArray *data = [[CoreDataStorageController sharedModel] selectElementFromEntity:@"STUFF" PredicateFromat:nil SortKey:nil Limit:0 Ascending:NO];
    return data;
}

+ (NSArray *)readDataFromStuff:(NSString *)uuid {
    NSArray *data = [[CoreDataStorageController sharedModel] selectElementFromEntity:@"STUFF" PredicateFromat:[NSPredicate predicateWithFormat:@"uuid == %@",uuid] SortKey:nil Limit:0 Ascending:NO];
    return data;
}

+ (NSArray *)readCategoryDataFromStuff:(NSNumber *)category {
    NSArray *data = [[CoreDataStorageController sharedModel] selectElementFromEntity:@"STUFF" PredicateFromat:[NSPredicate predicateWithFormat:@"category == %@",category] SortKey:nil Limit:0 Ascending:NO];
    return data;
}

+ (NSArray *)readSubcategoryDataFromStuff:(NSNumber *)category Sub:(NSNumber *)subcategory {
    NSArray *data = [[CoreDataStorageController sharedModel] selectElementFromEntity:@"STUFF" PredicateFromat:[NSPredicate predicateWithFormat:@"category == %@ && subcategory == %@",category,subcategory] SortKey:nil Limit:0 Ascending:NO];
    return data;
}

@end
